//
//  HuYu_RootViewController.m
//  mhkjjsd
//
//  Created by 凤利史 on 2018/5/22.
//  Copyright © 2018年 sunrose. All rights reserved.
//

#import "HuYu_RootViewController.h"
#import "HuYu_JiaoChengViewController.h"
#import "HuYu_QuanZhiViewController.h"
#import "HuYu_ZhiBoViewController.h"
#import "ZJScrollPageView.h"
@interface HuYu_RootViewController ()<ZJScrollPageViewDelegate>

@property (weak, nonatomic) ZJContentView *contentView;
@property (weak, nonatomic) ZJScrollSegmentView *segmentView;
@property(strong, nonatomic)NSMutableArray *titles;
@property(strong, nonatomic)NSArray<UIViewController<ZJScrollPageViewChildVcDelegate> *> *childVcs;

@end

@implementation HuYu_RootViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
   // [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationView];
    // Do any additional setup after loading the view.
}
- (void)creationView{
    
    //右边item
    UIButton *searchBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, screenScale(32), screenScale(31))];
    [searchBtn setTitle:@"互娱" forState:UIControlStateNormal];
    searchBtn.titleLabel.font = [UIFont fontWithName:@"DINEngschrift LT Alternate" size:16];
    [searchBtn setTitleColor:getColor(@"333333") forState:UIControlStateNormal];
    
    
    
    UIBarButtonItem *rightItme = [[UIBarButtonItem alloc]initWithCustomView:searchBtn];
    self.navigationItem.leftBarButtonItem = rightItme;
    
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, screenScale(30), screenScale(34))];
    [leftBtn setImage:[UIImage imageNamed:@"dynamic_notice_btn"] forState:UIControlStateNormal];
//    [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.rightBarButtonItem = leftBarBtn;
    
    
    UIView *threadView = [[UIView alloc]initWithFrame:CGRectMake(0, 1, DEF_SCREEN_WIDTH, 1)];
    threadView.backgroundColor = getColor(@"E6E6E6");
    [self.view addSubview:threadView];
    self.titles = @[@"圈子",
                    @"教程",
                    @"直播",
                    ].mutableCopy;
    
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    // 颜色渐变
    self.automaticallyAdjustsScrollViewInsets = NO;
    style.gradualChangeTitleColor = YES;
    style.scrollTitle = YES;
    style.autoAdjustTitlesWidth = YES;
    style.adjustCoverOrLineWidth = YES;
    style.normalTitleColor = [UIColor colorWithRed:153 / 255.0f green:153 / 255.0f blue:153 / 255.0f alpha:1];
    
    
    style.selectedTitleColor = [UIColor colorWithRed:51 / 255.0f green:51 / 255.0f blue:51 / 255.0f alpha:1];
    style.scrollLineColor = [UIColor colorWithRed:50 / 255.0f green:150 / 255.0f blue:251 / 255.0f alpha:1];
    
    style.segmentHeight = 40;
    self.childVcs = [self setupChildVc];
    
    __weak typeof(self) weakSelf = self;
    ZJScrollSegmentView *segment = [[ZJScrollSegmentView alloc] initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH-150, 40) segmentStyle:style delegate:self titles:self.titles titleDidClick:^(ZJTitleView *titleView, NSInteger indexID) {
        
        [weakSelf.contentView setContentOffSet:CGPointMake(weakSelf.contentView.bounds.size.width * indexID, 0.0) animated:YES];
        
    }];
    
    self.segmentView = segment;
    self.navigationItem.titleView = self.segmentView;
    
    ZJContentView *content = [[ZJContentView alloc] initWithFrame:CGRectMake(0, 1, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT-49-1) segmentView:self.segmentView parentViewController:self delegate:self];
    
    self.contentView = content;
    [self.view addSubview:self.contentView];
    
    
    
    
    NSLog(@"aaaaaaaa%@", self.titles);
}

#pragma mark ----------------ZJScrollPageViewDelegate---------------------
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}

- (NSArray *)setupChildVc {
    
    HuYu_QuanZhiViewController *vc1 = [HuYu_QuanZhiViewController new];
    
    HuYu_JiaoChengViewController *vc2 = [HuYu_JiaoChengViewController new];
    HuYu_ZhiBoViewController *vc3 = [HuYu_ZhiBoViewController new];
    NSArray *childVcs = [NSArray arrayWithObjects:vc1, vc2, vc3,  nil];
    return childVcs;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
    
    if (!childVc) {
        childVc = self.childVcs[index];
    }
    
    return childVc;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
